#!/bin/bash

# 安装依赖
yum install -y gcc make wget zlib-devel pam-devel

# 下载OpenSSH 9.7源码包
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.7p1.tar.gz

# 解压源码包
tar -zxvf openssh-9.7p1.tar.gz

# 进入源码目录
cd openssh-9.7p1

# 配置编译选项
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-privsep-path=/var/lib/sshd

# 编译并安装
make && make install

# 备份旧版本的sshd和ssh-keysign
cp /usr/sbin/sshd /usr/sbin/sshd.bak
cp /usr/sbin/ssh-keysign /usr/sbin/ssh-keysign.bak

# 创建软链接到新版本的sshd和ssh-keysign
ln -s /usr/sbin/sshd /usr/sbin/sshd-old
ln -s /usr/sbin/ssh-keysign /usr/sbin/ssh-keysign-old
ln -s /usr/local/sbin/sshd /usr/sbin/sshd
ln -s /usr/local/sbin/ssh-keysign /usr/sbin/ssh-keysign

# 重启sshd服务
systemctl restart sshd

# 清理源码包和解压文件
